home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Pascal / Games / Showwit! 1.0 / source code / Source / ShIntf.p < prev    next >
Encoding:
Text File  |  1996-02-14  |  27.9 KB  |  862 lines  |  [TEXT/PJMM]

  1. {****************************************************}
  2. {}
  3. {        ShIntf.p                                                                                                                                                                                                                        }
  4. {}
  5. {        Interface file for the Showwit! application.                                                                                                            }
  6. {}
  7. {        Showwit! is based on "Flippit" for the Amiga, as seen at Scitech Discovery            }
  8. {        Centre.    Showwit! uses the Sprite Animation Toolkit by Ingemar Ragnemalm.            }
  9. {}
  10. {        Showwit!                                                                                                                                                                                                                }
  11. {        Copyright © 1996 by Patrick C Hew. All rights reserved.                                                                }
  12. {}
  13. {        CBartenderHelpMenu                                                                                                                                                                                }
  14. {        Copyright © 1995 Patrick C Hew. All rights reserved.                                                                        }
  15. {}
  16. {        CHandlePrefs                                                                                                                                                                                                    }
  17. {        Copyright © 1993 by Peter Broadribb. All rights reserved.                                                            }
  18. {}
  19. {        CPixMap and CPixMapPane                                                                                                                                                            }
  20. {        Copyright © 1996 by Patrick C Hew. All rights reserved.                                                                }
  21. {}
  22. {        CProgressBar                                                                                                                                                                                                    }
  23. {        Copyright © 1994 by Johns Hopkins University. All rights reserved.                                }
  24. {}
  25. {        Sprite Animation Toolkit                                                                                                                                                                    }
  26. {        Copyright © 1992-1994 by Ingemar Ragnemalm. All rights reserved.                            }
  27. {}
  28. {        THINK Class Library 1.1.2                                                                                                                                                             }
  29. {        Copyright © 1989 by Symantec Corporation.     All rights reserved.                                        }
  30. {}
  31. {        Revision History:                                                                                                                                                                                        }
  32. {}
  33. {        Version:    1.0a1 for TCL 1.1.2 and SAT 2.3b4                                                                                                        }
  34. {        Date:             29 December 1995                                                                                                                                                        }
  35. {        Author:        Patrick C Hew     <phew@ucc.gu.uwa.edu.au>                                                                                }
  36. {        Notes:            First alpha .                                                                                                                                                                            }
  37. {}
  38. {        Version:    1.0b1 for TCL 1.1.2 and SAT 2.3b4                                                                                                        }
  39. {        Date:             27 January 1996                                                                                                                                                            }
  40. {        Author:        Patrick C Hew     <phew@ucc.gu.uwa.edu.au>                                                                                }
  41. {        Notes:            First beta .                                                                                                                                                                                }
  42. {}
  43. {        Version:    1.0b2 for TCL 1.1.2 and SAT 2.3b4                                                                                                        }
  44. {        Date:             4 February 1996                                                                                                                                                                }
  45. {        Author:        Patrick C Hew     <phew@ucc.gu.uwa.edu.au>                                                                                }
  46. {        Notes:            Second beta .                                                                                                                                                                            }
  47. {}
  48. {        Version:    1.0b3 for TCL 1.1.2 and SAT 2.3b4                                                                                                        }
  49. {        Date:             11 February 1996                                                                                                                                                            }
  50. {        Author:        Patrick C Hew     <phew@ucc.gu.uwa.edu.au>                                                                                }
  51. {        Notes:            Third beta / Preview release .                                                                                                                    }
  52. {}
  53. {        Version:    1.0 for TCL 1.1.2 and SAT 2.3b4                                                                                                                }
  54. {        Date:             16 February 1996                                                                                                                                                            }
  55. {        Author:        Patrick C Hew     <phew@ucc.gu.uwa.edu.au>                                                                                }
  56. {        Notes:            First release .                                                                                                                                                                        }
  57. {}
  58. {****************************************************}
  59.  
  60.  
  61. unit ShIntf;
  62.  
  63. interface
  64.  
  65.     uses
  66.         TCL, MoreTCL, TCL_Controls, TCL_Dialogs, TCL_Tables, CBartenderHelpMenu, CHandlePrefs, CPixMapPane, CProgressBar, SAT;
  67.  
  68.     const
  69.  
  70. { Command and resource IDs. Although we only need to put them }
  71. { in the required files, we do it this way to avoid clashes. }
  72. { Values for the application start with 2 (including about box). }
  73. { Values for the game director start with 3. }
  74. { Values for the documents start with 4. }
  75. { Values for the best player dialog start with 5. }
  76. { Values for the about/help dialog start with 6. }
  77.  
  78. { Command IDs. }
  79.  
  80.         cmdReadDefLevels = 2000;
  81.         cmdClearBestPlayers = 2001; { Also used by levels table, activated by game director. }
  82.         cmdHelp = 2002;
  83.  
  84.         cmdStartGame = 3000;
  85.         cmdClickStart = 3001;
  86.         cmdAbortGame = 3002;
  87.         cmdPauseGame = 3003;
  88.         cmdResumeGame = 3004;
  89.         cmdAnimationOn = 3005;
  90.         cmdSoundOn = 3006;
  91.         cmdChangeTargetPicture = 3007;
  92.         cmdResetTiles = 3008;
  93.  
  94.         cmdAboutScreen = 6000;
  95.         cmdHelpScreen = 6001;
  96.         cmdCreditsScreen = 6002;
  97.  
  98. { Resource IDs. }
  99.  
  100.         cicnHelp = 3000;
  101.         cicnPause = 3001;
  102.         cicnResume = 3002;
  103.         cicnAbort = 3003;
  104.         cicnTile = 3004;
  105.  
  106.         ALRTGamePlayingSoCannotOpen = 2000;
  107.  
  108.         DLOGNewBest = 5000;
  109.         DLOGAboutAndHelp = 6000;
  110.  
  111.         LEVLDefStart = 128;        { Easier to create levels with ResEdit if starting at 128. }
  112.         BESTDefStart = LEVLDefStart;
  113.  
  114.         PICTReaderColour = 2000;
  115.         PICTReaderBW = 2001;
  116.         PICTTitleColour = 3000;
  117.         PICTTitleBW = 3001;
  118.         PICTGameColour = 3002;
  119.         PICTGameBW = 3003;
  120.         PICTNewBestPlayerColour = 5000;
  121.         PICTNewBestPlayerBW = 5001;
  122.         PICTAboutColour = 6000;
  123.         PICTAboutBW = 6001;
  124.         PICTHelpColour = 6002;
  125.         PICTHelpBW = 6003;
  126.         PICTCreditsColour = 6004;
  127.         PICTCreditsBW = 6005;
  128.         PICTTargetColourBase = 10000;    { PICTs with IDs from 10000 may be used as targets. }
  129.         PICTTargetBWBase = 25000;    { If no colour quickdraw, assume B&W above this value. }
  130.  
  131.         STRlistAppMessages = 2000;
  132.         STRlistPrefMessages = 2001;
  133.         STRlistAppHelpMenu = 2002;
  134.         STRlistGameMessages = 3000;
  135.  
  136.         sndWelcome = 2000;
  137.         sndGameStarting = 3000;
  138.         sndGameComplete = 3001;
  139.         sndGameAborted = 3002;
  140.         sndNewBestPlayer = 5000;
  141.         sndFlipBase = 10000; { snds with IDs from 10000 may be used in flipping. }
  142.  
  143.         WINDReader = 2000;    { One resource for both the application and document readers. Windows are identical. }
  144.         WINDGame = 3000;
  145.  
  146. { The same sized window is used by the application and document level readers. }
  147.  
  148.         kReaderWindh = 300;
  149.         kReaderWindv = 100;
  150.  
  151.         kReaderTextLenh = kReaderWindh - 20;
  152.         kReaderTextLenv = 20;
  153.         kReaderTextPosh = 10;
  154.         kReaderTextPosv = 10;
  155.  
  156.         kReaderProgBarLenh = 260;
  157.         kReaderProgBarLenv = 20;
  158.         kReaderProgBarPosh = 20;
  159.         kReaderProgBarPosv = 40;
  160.  
  161.         kSTRAppReading = 1;
  162.  
  163. { Size of the target pictures, and the tiles used to hide it. }
  164.  
  165.         kTileSize = 64;
  166.         kTargetSize = kTileSize * 4;
  167.  
  168. { Structuring constants. }
  169.  
  170.         kMaxGridAcross = 4;    { Showwit! tile grid is 4x4. Change this only }
  171.         kMaxGridDown = 4;        { if you want to change all graphics and data! }
  172.         kMaxTiles = kMaxGridAcross * kMaxGridDown;
  173.  
  174.         kNullTile = 0;
  175.  
  176.         kNoLevel = 0;
  177.  
  178. { Resource Types. }
  179.  
  180.         kBESTResType = 'BEST';
  181.         kLEVLResType = 'LEVL';
  182.  
  183. { File Signatures. }
  184.  
  185.         kSignatureApplication = 'ShwI';
  186.         kSignatureLevelsFiles = 'ShwL';
  187.         kSignaturePreferencesFile = 'PREF';
  188.  
  189. { Preferences. }
  190.  
  191.         kNumberOfPrefs = 4;
  192.         kPrefAnimationOn = 1;
  193.         kPrefSoundOn = 2;
  194.         kPrefBestPlayers = 3;
  195.         kPrefNumBest = 4;
  196.  
  197.  
  198.     type
  199.  
  200. {    Think of the 4x4 grid as being 1 to 16, from numbered in the usual L-R, T-B manner. }
  201. {    This requires parsing the level resource for the starting and target configurations, }
  202. {    but overall, this is easier in terms of accessing arrays. }
  203.  
  204.         RowRange = 1..kMaxGridDown;
  205.         ColRange = 1..kMaxGridAcross;
  206.         TileRange = 1..kMaxTiles;
  207.  
  208.         LevelsRange = kNoLevel..maxInt;    { Positive integers… don't really want an upper bound. }
  209.  
  210. {    A level has a name and rules for how flipping a given tile affects the others. }
  211. {    We also store the details of the best performance for that level. }
  212.  
  213. {    In the original game (as seen at Scitech Discovery Centre, written by Arilia }
  214. {    Software), tiles were flipped from a starting to target configuration. In this }
  215. {    game, I've adopted an idea from Ingemar Ragnemalm to reveal a picture. Thus }
  216. {    without loss of generality, we can assume that we are going from some }
  217. {    starting configuration to all FALSE. }
  218.  
  219.         ConfigType = packed array[TileRange] of Boolean;
  220.  
  221.         DependantsType = array[TileRange] of TileRange;
  222.         TileRuleType = record
  223.                 theNumDep: TileRange;    { Including itself. }
  224.                 theDep: DependantsType; { Array being valid from 1..theNumDep. }
  225.             end;
  226.         RulesType = array[TileRange] of TileRuleType;
  227.  
  228.  
  229. {****************************************************}
  230. {}
  231. {        CShApp                                                                                                                                                                                                                        }
  232. {}
  233. {        Application class for the Showwit! application.                                                                                                    }
  234. {}
  235. {****************************************************}
  236.  
  237.     type
  238.         HandleArray = array[1..1] of Handle;
  239.         HandleArrayP = ^HandleArray;
  240.         HandleArrayH = ^HandleArrayP;
  241.  
  242. { Application is responsible for preparing sounds, which are used wherever necessary. }
  243.  
  244.     var
  245.         gSoundWelcome: Handle;
  246.         gSoundGameStarting, gSoundGameComplete, gSoundGameAborted: Handle;
  247.         gSoundNewBestPlayer: Handle;
  248.         gFlipSoundHandles: HandleArrayH;
  249.         gNumFlipSounds: Integer;
  250.  
  251.     type
  252.         CShApp = object(CApplication)
  253.  
  254.                 { Pointer to the application levels reader, when active. }
  255.                 itsAppLevelsDirector: CShAppLevelsDirector;
  256.  
  257.                 { Pointer to the director which looks after the game window. }
  258.                 itsGameDirector: CShGameDirector;
  259.  
  260.                 { Pointer to any open levels file. Only one level file is open at a time, if any. }
  261.                 itsLevelsDoc: CShLevelsDoc;
  262.  
  263.                 { Pointer to the preferences file. This is owned by the application, }
  264.                 { since there is no real need for a preferences director. The application }
  265.                 { levels reader also communicates with this object. }
  266.                 itsPrefsFile: CHandlePrefs;
  267.  
  268.                 { Construction of the application object, the application levels reader, }
  269.                 { the preferences file, the game director and initialization of the sounds. }
  270.                 procedure IShApp;
  271.  
  272.                 { Build a bartender which can handle the application help menu. }
  273.                 procedure MakeBartender;
  274.                 override;
  275.  
  276.                 { Recognized file types and the application signature. }
  277.                 procedure SetUpFileParameters;
  278.                 override;
  279.  
  280.                 { Insert the items into the application help menu. }
  281.                 procedure SetUpMenus;
  282.                 override;
  283.  
  284.                 { The application is responsible for calling up the about/help dialog, }
  285.                 { for calling the default levels reader, and for communicating with }
  286.                 { the levels document or preferences file about the best players. }
  287.                 procedure DoCommand (theCommand: longint);
  288.                 override;
  289.  
  290.                 { Handle the core apple events. The way in which we do so is }
  291.                 { different to that for a conventional application. }
  292.                 procedure DoAppleEvent (anAppleEvent: CAppleEvent);
  293.                 override;
  294.  
  295.                 { Handle the kAEOpenApplication AppleEvent, by loading the default levels. }
  296.                 procedure DoOpenAppEvent (anAppleEvent: CAppleEvent);
  297.  
  298.                 { Handle the kAEOpenDocuments AppleEvent, by the loading the first }
  299.                 { of any levels files. We only load the first, because only one file }
  300.                 { is open at any time. }
  301.                 procedure DoOpenOrPrintDocEvent (theEvent: CAppleEvent);
  302.                 override;
  303.  
  304.                 { The application is responsible for file commands, including the use }
  305.                 { of default levels. It also handles the help command. }
  306.                 procedure UpdateMenus;
  307.                 override;
  308.  
  309.                 { Loads the first of any preloaded levels files, then call StartUpAction. }
  310.                 { We only load the first, because only one file is open at any time. }
  311.                 procedure Preload;
  312.                 override;
  313.  
  314.                 { If there were no preloaded files, load the default levels. }
  315.                 procedure StartUpAction (numPreloads: Integer);
  316.                 override;
  317.  
  318.                 { We set our pointers to nil before exiting the application. The objects }
  319.                 {    to which they were pointing will be disposed of in inherited methods. }
  320.                 { Also dispose of the sounds and close the preferences file. }
  321.                 procedure ExitApp;
  322.                 override;
  323.  
  324.                 { Opens the given levels document. If a previous document is open, }
  325.                 { it needs to be closed first. }
  326.                 procedure OpenDocument (macSFReply: SFReply);
  327.                 override;
  328.  
  329.                 { Returns the director of the main game window. This is to allow }
  330.                 {    documents to send the list of levels to the game director. }
  331.                 function GameDirector: CShGameDirector;
  332.  
  333.                 { Returns the preferences file object. This allows access by both }
  334.                 {    the application and the reader of the default application levels. }
  335.                 function PreferencesFile: CHandlePrefs;
  336.  
  337.                 { The default levels have been read from the application resource, and }
  338.                 {    send to the game director. This is called at startup if necessary, or }
  339.                 {    as a menu command. }
  340.                 procedure ReadDefaultLevels;
  341.  
  342.                 { Tells the application levels director, or the active document, }
  343.                 {    to store the best player. }
  344.                 procedure StoreBestPlayer (aLevelNum: LevelsRange; aPlayer: Str15; aMoves: Integer; aTime: LongInt);
  345.  
  346.             end; { CShApp }
  347.  
  348.  
  349. {****************************************************}
  350. {}
  351. {        CShAppLevelsDirector                                                                                                                                                                            }
  352. {}
  353. {        Director class for reading in the default levels. Reads the levels from the                 }
  354. {        application resource, and the best players from the preferences file.                             }
  355. {}
  356. {        Although nominally this is a responsibility of the application, because we                    }
  357. {        draw a progress dialog, we need a separate director. This also brings us into     }
  358. {        line with the CShLevelsDoc, in that a separate object reads the levels and                }
  359. {        sends them to the game director.                                                                                                                                         }
  360. {}
  361. {****************************************************}
  362.  
  363.     { For obtaining best player information from the preferences file. }
  364.  
  365.     type
  366.         BestPlayerRec = record
  367.                 theLevelNum: LevelsRange;
  368.                 thePlayer: Str15;
  369.                 theMoves: Integer;
  370.                 theTime: LongInt;
  371.             end;
  372.         BestPlayerArray = array[1..1] of BestPlayerRec;
  373.         BestArrayPtr = ^BestPlayerArray;
  374.         BestArrayHand = ^BestArrayPtr;
  375.  
  376.     type
  377.         CShAppLevelsDirector = object(CDirector)
  378.  
  379.                 { Because the preferences file is a resource file, we need to store a }
  380.                 { reference to the original application resource file. }
  381.                 itsAppResFile: Integer;
  382.  
  383.                 { Pointer to the application object, so that we can get to the }
  384.                 { preferences object. }
  385.                 itsShApp: CShApp;
  386.  
  387.                 { Progress bar, indicating how far through we are. }
  388.                 itsProgBar: CProgressBar;
  389.  
  390.                 {    Construction of the application levels reader object. }
  391.                 procedure IShAppLevelsDirector (aSupervisor: CShApp; aAppResFile: Integer);
  392.  
  393.                 { Destruction of the application levels reader object. We set our pointers }
  394.                 {    to nil, for the objects to which they were pointing will be disposed of in }
  395.                 {    inherited methods. }
  396.                 procedure Free;
  397.                 override;
  398.  
  399.                 { Builds the window of the reader. }
  400.                 procedure BuildWindow;
  401.  
  402.                 { Returns the list of application levels, with best players as they exist. }
  403.                 { Updates the progress bar whilst doing so. }
  404.                 function AppLevels: CList;
  405.  
  406.                 { Stores the specified best player to the preferences file. }
  407.                 procedure StoreBestPlayer (aLevelNum: LevelsRange; aPlayer: Str15; aMoves: Integer; aTime: LongInt);
  408.  
  409.             end; { CShAppLevelsDirector }
  410.  
  411.  
  412. {****************************************************}
  413. {}
  414. {        CShBestPlayDirector                                                                                                                                                                                }
  415. {}
  416. {        DLOGDirector class for the director which gets the name of a best player.                }
  417. {}
  418. {****************************************************}
  419.  
  420.         CShBestPlayDirector = object(CDLOGDirector)
  421.  
  422.                 { Construct the director and dialog. }
  423.                 procedure IShBestPlayDirector (aSupervisor: CShGameDirector);
  424.  
  425.                 { Use a modal dialog to get the name of the best player. }
  426.                 procedure GetPlayerName (var aName: Str15);
  427.  
  428.             end; { CShBestPlayDirector }
  429.  
  430.  
  431. {****************************************************}
  432. {}
  433. {        CShTile                                                                                                                                                                                                                        }
  434. {}
  435. {        Pane class for the Showwit! tiles. When clicked, these tiles flip between hiding    }
  436. {     and showing a target picture. The target is a PixMap pane, and the pane is a            }
  437. {        "window" into the part of the picture concealed by the tile. The hiding side is        }
  438. {        a color icon, at the    centre of the pane. We override the DrawAll method to            }
  439. {        draw only one of these panes. We use a color icon so that the hiding side of the    }
  440. {        tile automatically adapts to the correct screen depth.    If Color QuickDraw is        }
  441. {        not present, then the color icon pane uses the black and white icons anyway.        }
  442. {}
  443. {****************************************************}
  444.  
  445.     type
  446.         TileState = (Showing, Hiding);
  447.  
  448.     type
  449.         CShTile = object(CPane)
  450.  
  451.                 { On one side is the PixMap pane, on the other side, the icon. }
  452.                 { In this way, the icon is draw at the correct depth. }
  453.                 itsPixMapPane: CPixMapPane;
  454.                 itsIcon: CIconPane;
  455.  
  456.                 { Whether we are showing or hiding the picture. }
  457.                 itsState: TileState;
  458.  
  459.                 { Position in the playing grid. }
  460.                 itsGridPos: TileRange;
  461.  
  462.                 { Pointer to the game director. }
  463.                 itsGameDirector: CShGameDirector;
  464.  
  465.                 { Construction of the Showwit! Tile object. }
  466.                 procedure IShTile (anEnclosure: CView; aSupervisor: CShGameDirector; aHEncl, aVEncl: integer; aHSizing, aVSizing: SizingOption);
  467.  
  468.                 { Destruction of the Showwit! Tile object. We set our pointers }
  469.                 {    to nil, for he objects to which they were pointing will be disposed of in }
  470.                 {    inherited methods. }
  471.                 procedure Free;
  472.                 override;
  473.  
  474.                 { Returns the current state of the tile, whether showing or hiding. }
  475.                 function GetState: TileState;
  476.  
  477.                 { Sets the state of the tile to showing or hiding as appropriate. }
  478.                 procedure SetState (aState: TileState);
  479.  
  480.                 {    The position of the tile in the grid has been set. }
  481.                 procedure SetGridPos (aGridPos: TileRange);
  482.  
  483.                 { Draw the target picture into the offscreen PixMap. }
  484.                 procedure SetTargetPICT (aPICTid: Integer);
  485.  
  486.                 { Draws either the hiding state or the target picture, as appropriate. }
  487.                 { Is essentially a pirate of the normal DrawAll method. }
  488.                 procedure DrawAll (var area: Rect);
  489.                 override;
  490.  
  491.                 { Sends a message to the game director to say that it has been clicked. }
  492.                 procedure DoClick (hitPt: Point; modifierKeys: integer; when: longint);
  493.                 override;
  494.  
  495.                 { Flips the tile, with animation and sound as appropriate. Sound on/off }
  496.                 { is controlled by SAT. }
  497.                 procedure DoFlip (aAnimate: Boolean);
  498.  
  499.             end; { CShTile }
  500.  
  501.  
  502. {****************************************************}
  503. {}
  504. {        CShGameDirector                                                                                                                                                                                        }
  505. {}
  506. {        Director for the main, game playing window of the Showwit! application.                     }
  507. {}
  508. {****************************************************}
  509.  
  510.     const
  511.         kNotPlaying = FALSE;
  512.         kPlaying = TRUE;
  513.  
  514.         kNotPaused = FALSE;
  515.         kPaused = TRUE;
  516.  
  517.         kNoSound = FALSE;
  518.         kSound = TRUE;
  519.  
  520.         kNoAnimation = FALSE;
  521.         kAnimation = TRUE;
  522.  
  523.     type
  524.         GameScreenType = (TitleScreen, GameScreen);
  525.  
  526.     type
  527.         TileGridType = array[TileRange] of CShTile;
  528.  
  529.     type
  530.         Str2 = string[2];    { For time. }
  531.  
  532.     type
  533.         IDArrayType = array[1..1] of Integer;
  534.         IDArrayP = ^IDArrayType;
  535.         IDArrayH = ^IDArrayP;
  536.  
  537.     type
  538.         CShGameDirector = object(CDirector)
  539.  
  540.                 { Pointer to the application. }
  541.                 itsShApp: CShApp;
  542.  
  543.                 { Level to start when the user says so. }
  544.                 itsStartLevel: LevelsRange;
  545.  
  546.                 { Current screen being displayed. }
  547.                 itsScreen: GameScreenType;
  548.  
  549.                 { When switching between screens, the window has different things showing. }
  550.                 { We thus need to keep a reference to the background picture. }
  551.  
  552.                 itsMainPicture: CPicture;
  553.  
  554.                 { Title screen panes, for hiding and showing. }
  555.  
  556.                 { We keep a reference of the levels table in order to know which level is }
  557.                 { selected, for the start button to be updated and to start the right level. }
  558.                 { The levels table owns the list of levels. }
  559.                 itsLevelsPane: CScrollPane;
  560.                 itsLevelsTable: CShLevelsTable;
  561.  
  562.                 { When clicked, the game starts. }
  563.                 itsStartButton: CButton;
  564.  
  565.                 { Game screen panes, for hiding and showing. }
  566.  
  567.                 { The level being played, and the players performance. }
  568.                 itsPlayData: CPane;
  569.                 itsNameText, itsMovesText, itsHoursText, itsMinutesText, itsSecondsText: CEditText;
  570.                 itsHoursStr, itsMinutesStr, itsSecondsStr: Str2;
  571.  
  572.                 { Controls for pausing, resuming and aborting play. }
  573.                 { Note that the help icon is always visible, so we do not need a reference for it. }
  574.                 itsPlayControls: CPane;
  575.                 itsPauseIcon, itsResumeIcon: CIconPane;
  576.  
  577.                 { The Showwit! tiles. }
  578.                 itsTiles: TileGridType;
  579.  
  580.                 { Target picture resource IDs. }
  581.  
  582.                 { Array of PICT ids for targets. }
  583.                 itsTargetPICTIDs: IDArrayH;
  584.                 itsNumTargetPICTs: Integer;
  585.  
  586.                 { When randomly selecting targets, avoid choosing the same one }
  587.                 { twice in a row. }
  588.                 itsLastPICTindex: Integer;
  589.  
  590.                 { Flags for whether playing or not, and if so, whether paused or not. }
  591.                 fPlaying, fPaused: Boolean;
  592.  
  593.                 { Record of the players performance. }
  594.                 itsMoves: Integer;
  595.                 itsLastStartTime, itsTimeBeforeLastStart, itsTimeSinceLastStart, itsTimeSinceLastStartOld: LongInt;
  596.  
  597.                 { Flags for special effects. }
  598.                 fAnimate, fSound: Boolean;
  599.  
  600.                 { We play the welcoming startup sound once and only once. }
  601.                 fWelcomingSoundPlayed: Boolean;
  602.  
  603.                 { Construction of the game director object. }
  604.                 procedure IShGameDirector (aSupervisor: CShApp);
  605.  
  606.                 { Destruction of the game director object. We set our pointers }
  607.                 {    to nil, for the objects to which they were pointing will be disposed of in }
  608.                 {    inherited methods. }
  609.                 procedure Free;
  610.                 override;
  611.  
  612.                 { The game director is responsible for reacting to game controls. }
  613.                 { It also checks for the Help item being selected from the Help Menu. }
  614.                 procedure DoCommand (theCommand: longint);
  615.                 override;
  616.  
  617.                 { Check for the help key being pressed. }
  618.                 procedure DoKeyDown (theChar: char; keyCode: Byte; macEvent: EventRecord);
  619.                 override;
  620.  
  621.                 { Respond to a click on the given tile. }
  622.                 procedure DoTileClicked (aTileNum: TileRange);
  623.  
  624.                 { Display the title screen. Possible cases are on startup, after a level is }
  625.                 { completed, or a game is aborted. }
  626.                 procedure DisplayTitleScreen (aCompletedLevel: Boolean);
  627.  
  628.                 { The game director is responsible for all commands related to playing the game, }
  629.                 { and the user preferences for animation and sound. }
  630.                 procedure UpdateMenus;
  631.                 override;
  632.  
  633.                 { The levels table communicates with the game director through the provider }
  634.                 { changed mechanism. If the list of levels has changed its selection, it records }
  635.                 {    the fact and informs the start button. }
  636.                 procedure ProviderChanged (aProvider: CCollaborator; reason: Longint; info: univ Ptr);
  637.                 override;
  638.  
  639.                 { If the game is progressing, update the clock. }
  640.                 procedure Dawdle (var maxSleep: longint);
  641.                 override;
  642.  
  643.                 { Installs the specified list of levels in the table. }
  644.                 procedure SetLevels (aLevels: CList);
  645.  
  646.                 { Returns TRUE if playing, FALSE otherwise. }
  647.                 function IsPlaying: Boolean;
  648.  
  649.             end; { CShGameDirector }
  650.  
  651.  
  652. {****************************************************}
  653. {}
  654. {        CShHelpDirector                                                                                                                                                                                            }
  655. {}
  656. {        DLOGDirector class for the director which handles the about/help dialog.                    }
  657. {}
  658. {****************************************************}
  659.  
  660.     type
  661.         HelpScreenType = (AboutScreen, HelpScreen, CreditsScreen);
  662.  
  663.     type
  664.         CShHelpDirector = object(CDLOGDirector)
  665.  
  666.                 { Single picture in which everything will be placed. }
  667.                 itsPicture: CPicture;
  668.  
  669.                 { Buttons for changing screens, or closing the dialog. }
  670.                 itsAboutButton, itsHelpButton, itsCreditsButton: CButton;
  671.  
  672.                 { Construction of the help director object. }
  673.                 procedure IShHelpDirector (aSupervisor: CShApp);
  674.  
  675.                 {    Destruction of the help director object. We set our pointers to nil, for the }
  676.                 {    objects to which they were pointing will be disposed of in inherited methods. }
  677.                 procedure Free;
  678.                 override;
  679.  
  680.                 {    The help director is responsible for changing between help screens. }
  681.                 procedure DoCommand (theCommand: longint);
  682.                 override;
  683.  
  684.                 { Continuous scrolling of the credits. }
  685.                 procedure Dawdle (var maxSleep: longint);
  686.                 override;
  687.  
  688.                 {    Set up the panes for each of the possible screens. }
  689.                 procedure SetDialogPanes (aScreenType: HelpScreenType);
  690.  
  691.                 { Enter the about/help dialog, starting from the given first screen. }
  692.                 procedure DoAboutAndHelp (aFirstScreen: HelpScreenType);
  693.  
  694.             end; { CShHelpDirector }
  695.  
  696.  
  697. {****************************************************}
  698. {}
  699. {        CShLevel                                                                                                                                                                                                                    }
  700. {}
  701. {        Object class for a level in the Showwit! game.                                                                                                    }
  702. {}
  703. {****************************************************}
  704.  
  705. {    Resource template for best player is used by the application to store to the }
  706. {    preferences file, by the levels documents to store to their own files, and }
  707. {    by the levels objects when reading in. }
  708.  
  709.     type
  710.         BESTtemplate = record
  711.                 thePlayer: Str15;
  712.                 theMoves: Integer;
  713.                 theTime: LongInt;
  714.             end;
  715.         BESTtemplateP = ^BESTtemplate;
  716.         BESTtemplateH = ^BESTtemplateP;
  717.  
  718.         CShLevel = object(CObject)
  719.  
  720.                 { Information about the level. }
  721.  
  722.                 itsName: Str15;
  723.                 itsStart: ConfigType;
  724.                 itsRules: RulesType;
  725.  
  726.                 { Information about the best player. }
  727.  
  728.                 itsPlayer: Str15;
  729.                 itsMoves: Integer;
  730.                 itsTime: LongInt;
  731.  
  732.                 { Set the level details from a LEVL resource. }
  733.                 procedure SetLEVL (LEVLid: Integer);
  734.  
  735.                 { Set the best player details from a BEST resource. }
  736.                 procedure SetBEST (BESTid: Integer);
  737.  
  738.                 {    Set the best player details to some safe, default values. }
  739.                 procedure SetDefaultBestPlayer;
  740.  
  741.                 { Returns the name of the level. }
  742.                 function GetName: Str15;
  743.  
  744.                 { Returns the starting configuration of the level. }
  745.                 function GetStart: ConfigType;
  746.  
  747.                 { Returns the rules for the level. }
  748.                 function GetRules: RulesType;
  749.  
  750.                 { Returns the name of the current best player of the level. }
  751.                 function GetPlayer: Str15;
  752.  
  753.                 { Sets the name of the current best player of the level. }
  754.                 procedure SetPlayer (aPlayer: Str15);
  755.  
  756.                 { Returns the moves taken by the current best player of the level. }
  757.                 function GetMoves: Integer;
  758.  
  759.                 { Sets the moves taken by the current best player of the level. }
  760.                 procedure SetMoves (aMoves: Integer);
  761.  
  762.                 { Returns the time taken by the current best player of the level. }
  763.                 function GetTime: LongInt;
  764.  
  765.                 { Sets the time taken by the current best player of the level. }
  766.                 procedure SetTime (aTime: LongInt);
  767.  
  768.             end; { CShLevel }
  769.  
  770.  
  771. {****************************************************}
  772. {}
  773. {        CShLevelsDoc                                                                                                                                                                                                    }
  774. {}
  775. {        Document class for the Showwit! application. Documents store levels                                }
  776. {        which can be played.                                                                                                                                                                                }
  777. {}
  778. {****************************************************}
  779.  
  780.     type
  781.         CShLevelsDoc = object(CDocument)
  782.  
  783.                 { Pointer to the application, so that we can send it the levels. }
  784.                 itsShApp: CShApp;
  785.  
  786.                 { Pointer to the file. }
  787.                 itsShLevelsFile: CResFile;
  788.  
  789.                 { Pointer to the progress bar. }
  790.                 itsProgBar: CProgressBar;
  791.  
  792.                 { Construction of the levels document object. }
  793.                 procedure IShLevelsDoc (aSupervisor: CShApp);
  794.  
  795.                 {    Destruction of the levels document object. We set our pointers to nil, for the }
  796.                 {    objects to which they were pointing will be disposed of in inherited methods. }
  797.                 procedure Free;
  798.                 override;
  799.  
  800.                 { Opens the levels file, reads the levels and then closes the document (we do }
  801.                 { not need the file open afterwards). Updates the progress bar whilst doing so. }
  802.                 procedure OpenFile (macSFReply: SFReply);
  803.                 override;
  804.  
  805.                 { Stores the specified best player to the levels file. }
  806.                 procedure StoreBestPlayer (aLevelNum: LevelsRange; aPlayer: Str15; aMoves: Integer; aTime: LongInt);
  807.  
  808.                 { Clears the best players from the levels file. }
  809.                 procedure ClearBestPlayers;
  810.  
  811.             end; { CShLevelsDoc }
  812.  
  813.  
  814. {****************************************************}
  815. {}
  816. {        CShLevelsTable                                                                                                                                                                                                }
  817. {}
  818. {        Array pane class for displaying the list of levels held by the game director.            }
  819. {}
  820. {****************************************************}
  821.  
  822.     type
  823.         CShLevelsTable = object(CArrayPane)
  824.  
  825.                 { Pointer to the game director. }
  826.                 itsGameDirector: CShGameDirector;
  827.  
  828.                 { Construction of the levels table object. }
  829.                 procedure CShLevelsTable.IShLevelsTable (anEnclosure: CView; aSupervisor: CShGameDirector; aWidth, aHeight, aHEncl, aVEncl: Integer; aHSizing, aVSizing: SizingOption);
  830.  
  831.                 {    Destruction of the levels table object. We set our pointers to nil, for the }
  832.                 {    objects to which they were pointing will be disposed of in inherited methods. }
  833.                 procedure Free;
  834.                 override;
  835.  
  836.                 { The levels table is responsible for clearing the players from its array, }
  837.                 { and then bouncing the command to the game director. }
  838.                 procedure DoCommand (theCommand: longint);
  839.                 override;
  840.  
  841.                 { The levels table is responsible for enabling the clear best players command. }
  842.                 procedure UpdateMenus;
  843.                 override;
  844.  
  845.                 { Do the double click command if return/enter is pressed. }
  846.                 procedure DoKeyDown (theChar: Char; keyCode: Byte; macEvent: EventRecord);
  847.                 override;
  848.  
  849.                 { Draw the level number, name and best player statistics. }
  850.                 procedure DrawCell (theCell: Cell; cellRect: Rect);
  851.                 override;
  852.  
  853.                 { Returns the index of the row in the table which is selected, 0 if none. }
  854.                 function RowSelected: LevelsRange;
  855.  
  856.             end; { CShLevelsTable }
  857.  
  858.  
  859. implementation
  860.  
  861.  
  862. end. { ShIntf }